- Write a program asking the user to enter a positive number. Validate the input. Using a for loop, print the sequence of numbers from 1 through the user's number, but print negative values for even numbers.
Sample run of program:
Enter a number positive number:
> -4
Invalid input! Enter a positive number:
> 7
1 -2 3 -4 5 -6 7
- Write a complete C++ program that asks the user to type a positive integer n. Validate the input. It should then ask the user to enter n more numbers and print out how many of these numbers were odd.
Sample run of program:
Enter a number positive number:
> -2
Invalid input! Enter a positive number:
> 4
Now enter 4 more integers:
> 6 7 8 9
2 were odd
Another sample run of program:
Enter a number positive number:
> 5
Now enter 5 more integers:
> 1 3 5 7 9
5 were odd
- Write a complete C++ program that asks the user to type two positive integers. Validate the input. It should show a horizontal bar of X symbols whose length is given by the shorter of the two integers. (If the two integers are equal, either can be used as the shorter.)
Sample run of program:
Enter two positive integers:
> 4 2
XX
Another sample run of program:
Enter two positive integers:
> 4 5
XXXX
- (Variation of the FizzBuzz Test programming question.) Write a complete C++ program that does the following:
- Prompts the user to enter a positive integer greater than 10.
- If the user enters an invalid number, force the user to enter a correct value.
- Using a for loop, print the sequence of numbers from 1 through the user's number, except:
- Print "Fuzzy" for numbers that are multiples of 3.
- Print "Cat" for numbers that are multiples of 4.
- Print "FuzzyCat" for numbers that are multiples of both 3 and 4.
Sample run of program:
Enter positive integer greater than 10: 9
Invalid input! Try again: 16
1 2 Fuzzy Cat 5 Fuzzy 7 Cat Fuzzy 10 11 FuzzyCat 13 14 Fuzzy Cat
- Write a complete C++ program that does the following:
- Prompts the user for two integers.
- Negative numbers are acceptable inputs
- The second number entered must be at least 20 greater than the first number. In other words, if you subtract the first number from the second, the difference must be at least 20
- If the user's input does not match the input requirements, force the user to enter valid input.
- Print the numbers between the smaller input and the larger input that are evenly divisible by 2 but not evenly divisible by 3.
Sample run of program:
Enter two integers. The second must be at least 20 larger than the first: 4 18
Invalid input! Try again: 4 28
The numbers between 4 and 28 that are evenly divisible by 2 but not by 3 are:
4 8 10 14 16 20 22 26 28
Another sample run of the program:
Enter two integers. The second must be at least 20 larger than the first: 5 19
Invalid input! Try again: -5 19
The numbers between -5 and 19 that are evenly divisible by 2 but not by 3 are:
-4 -2 2 4 8 10 14 16